package com.ruoyi.web.api.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.qo.AlertListQo;
import com.ruoyi.system.domain.vo.AlertListVo;
import com.ruoyi.system.domain.vo.IndexVo;
import com.ruoyi.system.service.ISysAlertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 预警列表操作处理
 *
 * @author ruoyi
 */
@Api(tags = "预警列表管理")
@RestController
@RequestMapping("/alert")
public class SysAlertController extends BaseController {

    private final ISysAlertService sysAlertService;

    public SysAlertController(ISysAlertService sysAlertService) {
        this.sysAlertService = sysAlertService;
    }

    /**
     * 获取预警列表
     */
    @ApiOperation(value = "获取预警列表", notes = "获取所有预警信息")
    @GetMapping("/list")
    public TableDataInfo list(AlertListQo alertListQo) {
        startPage();
        List<AlertListVo> list = sysAlertService.selectAlertList(alertListQo);
        return getDataTable(list);
    }

    /**
     * 根据预警编号获取详细信息
     */
    @ApiOperation(value = "获取预警详细信息", notes = "根据id获取预警详细信息")
    @ApiImplicitParam(name = "id", value = "预警ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(sysAlertService.selectSysAlertById(id));
    }

    /**
     * 根据预警编号获取详细信息
     */
    @ApiOperation(value = "获取预警详细信息", notes = "根据id获取预警详细信息")
    @ApiImplicitParam(name = "id", value = "预警ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/detail")
    public AjaxResult detail(@RequestParam Long id) {
        return success(sysAlertService.getAlertDetailById(id));
    }


    @GetMapping("/stat/level-name")
    @ApiOperation("按预警等级和预警名称统计预警数量")
    public AjaxResult statAlertByLevelAndName() {
        return AjaxResult.success(sysAlertService.countAlertByLevelAndName());
    }

    /**
     * 根据区域编号获取详细信息
     */
    @ApiOperation(value = "获取服务用户数量", notes = "获取服务用户数量")
    @GetMapping(value = "/getTodayAlertCount")
    public AjaxResult getTodayAlertCount() {
        return success(sysAlertService.getTodayAlertCount());
    }

    /**
     * 按分钟统计预警信息
     */
    @ApiOperation("按分钟统计预警信息")
    @GetMapping("/stats/minutes")
    public AjaxResult getMinutesStats(Long minutes) {
        Map<String, List<IndexVo>> stats = sysAlertService.countAlertByMinutes(minutes);
        return AjaxResult.success(stats);
    }

    /**
     * 按小时统计当天的预警信息
     */
    @ApiOperation("按小时统计当天的预警信息")
    @GetMapping("/stats/hourly")
    public AjaxResult getHourlyStats() {
        Map<String, List<IndexVo>> stats = sysAlertService.countAlertByHour();
        return AjaxResult.success(stats);
    }

    /**
     * 按天统计当月的预警信息
     */
    @ApiOperation("按天统计当月的预警信息")
    @GetMapping("/stats/daily")
    public AjaxResult getDailyStats() {
        Map<String, List<IndexVo>> stats = sysAlertService.countAlertByDay();
        return AjaxResult.success(stats);
    }
}